package com.mall.controller.sys;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mall.entity.sys.ResEO;
import com.mall.entity.sys.UserEO;
import com.mall.service.sys.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;



/**
 * <p>
 *  管理登录权限控制类
 * </p>
 *
 * @author hxyool
 * @since 2020-06-24
 */
@Api(tags = "权限数据接口")
@RestController
@RequestMapping("/sys")
public class LoginController {

	
	@Autowired
	private IUserService service;
	
	@ApiOperation(value = "用户登录",notes="根据用户名，密码登录系统")
	@ApiImplicitParams({//
		@ApiImplicitParam(paramType="query",name="username",value="用户名",required=true),//
		@ApiImplicitParam(paramType="query",name="password",value="密码", required=true),//
	})
	@PostMapping("/login")
	public ResEO login(@RequestParam String username , @RequestParam String password) {
		
		ResEO res = new ResEO();
			try {
				QueryWrapper<UserEO> qw = 	new QueryWrapper<>();
				qw.eq("username", username);
				qw.eq("password", password);
				UserEO one = service.getOne(qw);
				if(one == null){
					res.setStatus(1);//业务异常 用户名密码错误
					res.setMsg("用户名或者密码错误");
				}else {
					res.setMsg("登录成功，正在跳转页面");
				}
			} catch (Exception e) {
				e.printStackTrace();
				res.setStatus(-1);
			} 
			
			return res;
		
	}
	
}
